package com.huang.wishstar.generator;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class Generator {
    public static void main(String[] args) {
        //创建generator对象
        AutoGenerator autoGenerator = new AutoGenerator();
        //数据源
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL);
        dataSourceConfig.setUrl("jdbc:mysql://8.136.195.245:4690/WishStar?useUnicode=true&characterEncoding=UTF-8");
        dataSourceConfig.setUsername("developer");
        dataSourceConfig.setPassword("hmx123?!asd456jkl");
        dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
        autoGenerator.setDataSource(dataSourceConfig);
        //全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir(System.getProperty("user.dir")+"/src/main/java");//System.getProperty("user.dir") 就是当前工程的绝对目录
        globalConfig.setOpen(false);//创建好工程之后不会自动打开
        globalConfig.setAuthor("hmx");
        globalConfig.setServiceName("%sService");//加上这句代码，在生成Service类的时候就不会默认前面有I了
        autoGenerator.setGlobalConfig(globalConfig);
        //包信息
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent("com.huang.wishstar");
//        packageConfig.setModuleName("generator");
        packageConfig.setModuleName("");
        packageConfig.setController("controller");
        packageConfig.setService("service");
        packageConfig.setServiceImpl("service.impl");
        packageConfig.setMapper("mapper");
        packageConfig.setEntity("entity");
        autoGenerator.setPackageInfo(packageConfig);
        //配置策略
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setEntityLombokModel(true);//实体类生成之后自动添加lombok注解
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);//驼峰转换
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);//将数据库中带下划线的转成驼峰规则
        autoGenerator.setStrategy(strategyConfig);
//        strategyConfig.setInclude("wish","habit");//只会生成指定的表
        strategyConfig.setInclude("wish");//只会生成指定的表

        //配置完之后运行
        autoGenerator.execute();
    }
}
